package com.ccys.common.third.sms;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.DependsOn;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * 三方参数 读取当前包下的sms.properties
 * <p>
 * 当本地启动时，因为不存在file路径，所以会加载classpath；
 * 当jar启动时，若file路径不存在，会加载classpath；反之会加载file路径同时覆盖classpath路径下的内容；
 * ignoreResourceNotFound = true 一定要加上，否则找不到会报错。加上之后会忽略找不到的配置文件。
 *
 * @author Administrator
 */
@Component
@PropertySource(value = {"classpath:config/sms.properties", "file:./config/sms.properties", "file:./../config/sms.properties"}, ignoreResourceNotFound = true, encoding = "utf-8")
public class SmsConstants {


    public static String NEXMO_URL;
    public static String SENDER_NAME;
    public static String NEXMO_API_KEY;
    public static String NEXMO_API_SECRET;


    @Value("${nexmo.url}")
    public void setLingKaiSignature(String nexmoUrl) {
        if (StringUtils.isNotBlank(nexmoUrl)) {
            nexmoUrl = nexmoUrl.trim();
        }
        SmsConstants.NEXMO_URL = nexmoUrl;
    }
    @Value("${sender_name}")
    public void setSenderName(String senderName) {
        if (StringUtils.isNotBlank(senderName)) {
            senderName = senderName.trim();
        }
        SmsConstants.SENDER_NAME = senderName;
    }
    @Value("${nexmo.api.key}")
    public void setNexmoApiKey(String nexmoApiKey) {
        if (StringUtils.isNotBlank(nexmoApiKey)) {
            nexmoApiKey = nexmoApiKey.trim();
        }
        SmsConstants.NEXMO_API_KEY = nexmoApiKey;
    }
    @Value("${nexmo.api.secret}")
    public void setNexmoApiSecret(String nexmoApiSecret) {
        if (StringUtils.isNotBlank(nexmoApiSecret)) {
            nexmoApiSecret = nexmoApiSecret.trim();
        }
        SmsConstants.NEXMO_API_SECRET = nexmoApiSecret;
    }

}
